package pages;

import core.TestBase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import utils.Log4Test;

import java.util.List;

/**
 * Created by gzhovnuvaty on 7/8/14.
 */
public class NoteBookPage extends TestBase {
    protected By isNotebook = By.xpath("//div[@class='m-main-i active']/a[@class='m-main-title']");
    protected WebElement isNotebookPresent;
    protected By manufactureBlock = By.xpath(".//ul[@class='m-cat-l']/li[2]/ul/li/a");
    protected List<WebElement> manufactureBlockList;


    public String verifyNotebook(){
        Log4Test.info("Verify that Notebook page is opened");
        isNotebookPresent = webDriver.findElement(isNotebook);
        return isNotebookPresent.getAttribute("name");
    }




    public int getManufactureCount(){
       Log4Test.info("Verify block of manufactures contains 8 element");
       manufactureBlockList = webDriver.findElements(manufactureBlock);
       int i=0;
       for(WebElement manufacture: manufactureBlockList){
           i++;
       }
       return i;

    }


    public void findAndClickApple(){
        Log4Test.info("Find Apple and click it");
        manufactureBlockList = webDriver.findElements(manufactureBlock);
        for (WebElement elem: manufactureBlockList){
            if (elem.getText().equals("Apple")){
                elem.click();
                break;
            }
        }
    }
}
